﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XTYAPI.PLC
{
    /// <summary>
    /// 解码
    /// 使用“解码”指令，在输出值中将输入值所指定的位置位。
    ///“解码”指令读取参数 IN 的值，并设置输出值中的某个位，该位位置与读取的值一致。输出值中的其它位以零填充。
    /// </summary>
   public class DECO 
    {
        bool[] byteResult;
        bool[] shortResult;
        bool[] intResult;
        bool[] longResult;
        public bool[] DECO_Byte(byte value)
        {
            if (byteResult == null)
            {
                byteResult = new bool[8];
            }
            for (int i = 0; i < byteResult.Length; i++)
            {
                byteResult[i]= (value & 1 << i) > 0;
            }
            return byteResult;
        }
        public bool[] DECO_Short(short value)
        {
            if (shortResult==null)
            {
                shortResult = new bool[16];
            }
            for (int i = 0; i < shortResult.Length; i++)
            {
                shortResult[i] = (value & 1 << i) > 0;
            }
            return shortResult;
        }
        public bool[] DECO_Int(int value)
        {
            if (intResult == null)
            {
                intResult = new bool[32];
            }
            for (int i = 0; i < intResult.Length; i++)
            {
                intResult[i] = (value & 1 << i) > 0;
            }
            return intResult;
        }
        public bool[] DECO_Long(long value)
        {
            if (longResult == null)
            {
                longResult = new bool[64];
            }
            for (int i = 0; i < longResult.Length; i++)
            {
                longResult[i] = (value & 1 << i) > 0;
            }
            return longResult;
        }
    }
}
